home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / components / nsBrowserGlue.js < prev    next >
Text File  |  2006-05-08  |  8KB  |  251 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is the Firefox Browser Glue Service.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Giorgio Maone
  18.  * Portions created by the Initial Developer are Copyright (C) 2005
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Giorgio Maone <g.maone@informaction.com>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38.  
  39.  
  40. // Constructor
  41.  
  42. function BrowserGlue() {
  43.   this._init();
  44. }
  45.  
  46. BrowserGlue.prototype = {
  47.   QueryInterface: function(iid) 
  48.   {
  49.      xpcomCheckInterfaces(iid, kServiceIIds, Components.results.NS_ERROR_NO_INTERFACE);
  50.      return this;
  51.   }
  52. ,
  53.   // nsIObserver implementation 
  54.   observe: function(subject, topic, data) 
  55.   {
  56.     switch(topic) {
  57.       case "xpcom-shutdown":
  58.         this._dispose();
  59.         break;
  60.       case "profile-change-teardown": 
  61.         this._onProfileShutdown();
  62.         break;
  63.       case "final-ui-startup":
  64.         this._onProfileStartup();
  65.         break;
  66.     }
  67.   }
  68.   // initialization (called on application startup) 
  69.   _init: function() 
  70.   {
  71.     // observer registration
  72.     const osvr = Components.classes['@mozilla.org/observer-service;1']
  73.                            .getService(Components.interfaces.nsIObserverService);
  74.     osvr.addObserver(this, "profile-change-teardown", false);
  75.     osvr.addObserver(this, "xpcom-shutdown", false);
  76.     osvr.addObserver(this, "final-ui-startup", false);
  77.   },
  78.  
  79.   // cleanup (called on application shutdown)
  80.   _dispose: function() 
  81.   {
  82.     // observer removal 
  83.     const osvr = Components.classes['@mozilla.org/observer-service;1']
  84.                            .getService(Components.interfaces.nsIObserverService);
  85.     osvr.removeObserver(this, "profile-change-teardown");
  86.     osvr.removeObserver(this, "xpcom-shutdown");
  87.     osvr.removeObserver(this, "final-ui-startup");
  88.   },
  89.  
  90.   // profile startup handler (contains profile initialization routines)
  91.   _onProfileStartup: function() 
  92.   {
  93.     this.Sanitizer.onStartup();
  94.     // check if we're in safe mode
  95.     var app = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo)
  96.                         .QueryInterface(Components.interfaces.nsIXULRuntime);
  97.     if (app.inSafeMode) {
  98.       var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  99.                          .getService(Components.interfaces.nsIWindowWatcher);
  100.       ww.openWindow(null, "chrome://browser/content/safeMode.xul", 
  101.                     "_blank", "chrome,centerscreen,modal,resizable=no", null);
  102.     }
  103.   },
  104.  
  105.   // profile shutdown handler (contains profile cleanup routines)
  106.   _onProfileShutdown: function() 
  107.   {
  108.     // here we enter last survival area, in order to avoid multiple
  109.     // "quit-application" notifications caused by late window closings
  110.     const appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1']
  111.                                  .getService(Components.interfaces.nsIAppStartup);
  112.     try {
  113.       appStartup.enterLastWindowClosingSurvivalArea();
  114.  
  115.       this.Sanitizer.onShutdown();
  116.  
  117.     } catch(ex) {
  118.     } finally {
  119.       appStartup.exitLastWindowClosingSurvivalArea();
  120.     }
  121.   },
  122.  
  123.   // returns the (cached) Sanitizer constructor
  124.   get Sanitizer() 
  125.   {
  126.     if(typeof(Sanitizer) != "function") { // we should dynamically load the script
  127.       Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
  128.                 .getService(Components.interfaces.mozIJSSubScriptLoader)
  129.                 .loadSubScript("chrome://browser/content/sanitize.js", null);
  130.     }
  131.     return Sanitizer;
  132.   },
  133.   
  134.   // ------------------------------
  135.   // public nsIBrowserGlue members
  136.   // ------------------------------
  137.   
  138.   sanitize: function(aParentWindow) 
  139.   {
  140.     this.Sanitizer.sanitize(aParentWindow);
  141.   }
  142.  
  143. }
  144.  
  145.  
  146. // XPCOM Scaffolding code
  147.  
  148. // component defined in this file
  149.  
  150. const kServiceName = "Firefox Browser Glue Service";
  151. const kServiceId = "{eab9012e-5f74-4cbc-b2b5-a590235513cc}";
  152. const kServiceCtrId = "@mozilla.org/browser/browserglue;1";
  153. const kServiceConstructor = BrowserGlue;
  154.  
  155. const kServiceCId = Components.ID(kServiceId);
  156.  
  157. // interfaces implemented by this component
  158. const kServiceIIds = [ 
  159.   Components.interfaces.nsIObserver,
  160.   Components.interfaces.nsISupports,
  161.   Components.interfaces.nsISupportsWeakReference,
  162.   Components.interfaces.nsIBrowserGlue
  163.   ];
  164.  
  165. // categories which this component is registered in
  166. const kServiceCats = ["app-startup"];
  167.  
  168. // Factory object
  169. const kServiceFactory = {
  170.   _instance: null,
  171.   createInstance: function (outer, iid) 
  172.   {
  173.     if (outer != null) throw Components.results.NS_ERROR_NO_AGGREGATION;
  174.  
  175.     xpcomCheckInterfaces(iid, kServiceIIds, 
  176.                           Components.results.NS_ERROR_INVALID_ARG);
  177.     return this._instance == null ?
  178.       this._instance = new kServiceConstructor() : this._instance;
  179.   }
  180. };
  181.  
  182. function xpcomCheckInterfaces(iid, iids, ex) {
  183.   for (var j = iids.length; j-- >0;) {
  184.     if (iid.equals(iids[j])) return true;
  185.   }
  186.   throw ex;
  187. }
  188.  
  189. // Module
  190.  
  191. var Module = {
  192.   registered: false,
  193.   
  194.   registerSelf: function(compMgr, fileSpec, location, type) 
  195.   {
  196.     if (!this.registered) {
  197.       compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar)
  198.              .registerFactoryLocation(kServiceCId,
  199.                                       kServiceName,
  200.                                       kServiceCtrId, 
  201.                                       fileSpec,
  202.                                       location, 
  203.                                       type);
  204.       const catman = Components.classes['@mozilla.org/categorymanager;1']
  205.                                .getService(Components.interfaces.nsICategoryManager);
  206.       var len = kServiceCats.length;
  207.       for (var j = 0;  j < len; ++j) {
  208.         catman.addCategoryEntry(kServiceCats[j],
  209.           kServiceCtrId, kServiceCtrId, true, true, null);
  210.       }
  211.       this.registered = true;
  212.     } 
  213.   },
  214.   
  215.   unregisterSelf: function(compMgr, fileSpec, location) 
  216.   {
  217.     compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar)
  218.            .unregisterFactoryLocation(kServiceCId, fileSpec);
  219.     const catman = Components.classes['@mozilla.org/categorymanager;1']
  220.                              .getService(Components.interfaces.nsICategoryManager);
  221.     var len = kServiceCats.length;
  222.     for (var j = 0;  j < len; ++j) {
  223.       catman.deleteCategoryEntry(kServiceCats[j], kServiceCtrId, true);
  224.     }
  225.   },
  226.   
  227.   getClassObject: function(compMgr, cid, iid) 
  228.   {
  229.     if(cid.equals(kServiceCId))
  230.       return kServiceFactory;
  231.     
  232.     throw Components.results[
  233.       iid.equals(Components.interfaces.nsIFactory)
  234.       ? "NS_ERROR_NO_INTERFACE"
  235.       : "NS_ERROR_NOT_IMPLEMENTED"
  236.     ];
  237.     
  238.   },
  239.   
  240.   canUnload: function(compMgr) 
  241.   {
  242.     return true;
  243.   }
  244. };
  245.  
  246. // entrypoint
  247. function NSGetModule(compMgr, fileSpec) {
  248.   return Module;
  249. }
  250.